﻿using System.Collections;
using BitBenderGames;
using DG.Tweening;
using FlowCanvas.Nodes;
using UnityEngine;

namespace Yoozoo.Gameplay.Liberty.Nodes
{
    public class CameraZoomNode : LatentActionNode<GameCameraEnum, float, float, Ease>
    {
        public override bool allowRoutineQueueing { get { return false; } }
        
        public override IEnumerator Invoke(GameCameraEnum cameraEnum, float zoom, float duration, Ease ease)
        {
            Camera camera = BlueprintUtils.GetCamera(cameraEnum);
            if (camera)
            {
                var moveComponent = camera.GetComponentInChildren<CameraMoveComponent>();
                if (moveComponent)
                {
                    bool complete = false;
                    moveComponent.ZoomTo(zoom,duration,ease,(() =>
                    {
                        complete = true;
                    }));

                    yield return new UnityEngine.WaitUntil(() => complete);
                }                
            }
        }
    }
}